{% extends "admin/layout.html" %}

{% block title %}审批流程详情 - {{ super() }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">审批流程详情: {{ flow.name }}</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
        <a href="{{ url_for('approval.edit_flow', flow_id=flow.id) }}" class="btn btn-sm btn-outline-primary me-2">
            <i class="fas fa-edit"></i> 编辑
        </a>
        <a href="{{ url_for('approval.flow_list') }}" class="btn btn-sm btn-outline-secondary">
            <i class="fas fa-arrow-left"></i> 返回列表
        </a>
    </div>
</div>

<div class="row">
    <div class="col-md-6">
        <div class="card shadow-sm mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">基本信息</h5>
            </div>
            <div class="card-body">
                <table class="table table-borderless">
                    <tr>
                        <th width="120">流程名称:</th>
                        <td>{{ flow.name }}</td>
                    </tr>
                    <tr>
                        <th>描述:</th>
                        <td>{{ flow.description or '无' }}</td>
                    </tr>
                    <tr>
                        <th>关联部门:</th>
                        <td>{{ flow.department.name if flow.department else '通用' }}</td>
                    </tr>
                    <tr>
                        <th>是否默认:</th>
                        <td>
                            {% if flow.is_default %}
                            <span class="badge bg-success">是</span>
                            {% else %}
                            <span class="badge bg-secondary">否</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th>创建时间:</th>
                        <td>{{ flow.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>

    <div class="col-md-6">
        <div class="card shadow-sm mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">审批步骤</h5>
            </div>
            <div class="card-body">
                {% if flow.steps %}
                <ol class="list-group list-group-numbered">
                    {% for step in flow.steps|sort(attribute='order') %}
                    <li class="list-group-item d-flex justify-content-between align-items-start">
                        <div class="ms-2 me-auto">
                            <div class="fw-bold">{{ step.user.name }}</div>
                            {{ step.user.department.name if step.user.department }}
                            {% if step.require_comment %}
                            <span class="badge bg-info mt-1">需填写意见</span>
                            {% endif %}
                        </div>
                    </li>
                    {% endfor %}
                </ol>
                {% else %}
                <p class="text-muted">暂无审批步骤</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>

{% if projects %}
<div class="card shadow-sm">
    <div class="card-header">
        <h5 class="card-title mb-0">使用此流程的项目</h5>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>项目名称</th>
                        <th>状态</th>
                        <th>负责人</th>
                        <th>创建时间</th>
                    </tr>
                </thead>
                <tbody>
                    {% for project in projects %}
                    <tr>
                        <td>{{ project.name }}</td>
                        <td>
                            <span class="badge bg-{{
                                'secondary' if project.status == 'draft'
                                else 'warning' if project.status == 'pending_review'
                                else 'success' if project.status == 'approved'
                                else 'danger' if project.status == 'rejected'
                                else 'primary' if project.status == 'in_progress'
                                else 'info' if project.status == 'completed'
                                else 'dark'
                            }}">
                                {{ project.status }}
                            </span>
                        </td>
                        <td>{{ project.owner.name }}</td>
                        <td>{{ project.created_at.strftime('%Y-%m-%d') }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endif %}
{% endblock %}